home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / programming / e / lsestuff2 / myappicon.e < prev    next >
Text File  |  1999-11-29  |  4KB  |  127 lines

  1. -> appicon.e -- Show use of an AppIcon
  2.  
  3. -> omgjord 990320 av LS .. myappicon.e
  4. -> funktion : dubbelklick avslutar.
  5. ->            information om filer och
  6. ->            lådor som släpps på iconen
  7. ->            ges som argument till
  8. ->
  9.  
  10.  
  11. -> 990422 -> snyggar upp och lägger till
  12. -> lite argument... man kan välja diskobject
  13. -> och namn på appiconen. dessutom vilken kommandorad
  14. -> som ska köras med det man 'appar' efter.
  15.  
  16. ->990427 : lade till FOREACH , Added FOREACH
  17.  
  18.  
  19. OPT OSVERSION=37
  20.  
  21. MODULE 'icon', 'dos/var',
  22.        'wb',
  23.        'workbench/startup',
  24.        'workbench/workbench'
  25.  
  26. ENUM ERR_NONE, ERR_APPICON, ERR_DOBJ, ERR_LIB, ERR_PORT, ERR_ARG
  27.  
  28. RAISE ERR_APPICON IF AddAppIconA()=NIL,
  29.       ERR_DOBJ    IF GetDefDiskObject()=NIL,
  30.       ERR_LIB     IF OpenLibrary()=NIL,
  31.       ERR_PORT    IF CreateMsgPort()=NIL,
  32.       ERR_ARG     IF ReadArgs()=NIL
  33.  
  34.   DEF dobj=NIL:PTR TO diskobject, myport=NIL, appicon=NIL,
  35.       appmsg:PTR TO appmessage, alive=TRUE, x,
  36.       ->LS
  37.       nfl[100]:ARRAY OF CHAR,
  38.       argstring[100]:STRING,
  39.       myargs:PTR TO LONG,
  40.       rdargs
  41.  
  42.  
  43. PROC main() HANDLE
  44.   myargs:=[0,0,0,0]
  45.   rdargs:=ReadArgs('COMMAND/A,ICON/K,NAME/K,FOREACH/S', myargs, NIL)
  46.  
  47.   -> Get the the right version of the Icon Library, initialise iconbase
  48.   iconbase:=OpenLibrary('icon.library', 37)
  49.   -> Get the the right version of the Workbench Library
  50.   workbenchbase:=OpenLibrary('workbench.library', 37)
  51.   -> This is the easy way to get some icon imagery
  52.   -> Real applications should use custom imagery
  53.   dobj:=GetDiskObject(
  54.   IF myargs[1] THEN myargs[1] ELSE 'myappicon')
  55.   -> The type must be set to NIL for a WBAPPICON
  56.   dobj.type:=NIL
  57.  
  58.   -> The CreateMsgPort() function is in Exec version 37 and later only
  59.   myport:=CreateMsgPort()
  60.   -> Put the AppIcon up on the Workbench window
  61.   appicon:=AddAppIconA(0, 0,
  62.   IF myargs[2] THEN myargs[2] ELSE 'MyAppIcon',
  63.   myport, NIL, dobj, NIL)
  64.  
  65.   WHILE alive
  66.     -> Here's the main event loop where we wait for  messages to show up
  67.     -> from the AppIcon
  68.     WaitPort(myport)
  69.  
  70.     -> Might be more than one message at the port...
  71.     WHILE appmsg:=GetMsg(myport)
  72.       IF appmsg.numargs=0
  73.         -> If numargs is 0 the AppIcon was activated directly
  74.        -> avsluta  *****
  75.        alive:=FALSE
  76.       ELSEIF appmsg.numargs>0
  77.          IF myargs[3] THEN foreach() ELSE oneshot()
  78.       ENDIF
  79.       -> Let Workbench know we're done with the message
  80.       ReplyMsg(appmsg)
  81.     ENDWHILE
  82.   ENDWHILE
  83.  
  84. EXCEPT DO
  85.   IF appicon THEN RemoveAppIcon(appicon)
  86.   IF myport
  87.     -> Clear away any messages that arrived at the last moment
  88.     WHILE appmsg:=GetMsg(myport) DO ReplyMsg(appmsg)
  89.     DeleteMsgPort(myport)
  90.   ENDIF
  91.   IF dobj THEN FreeDiskObject(dobj)
  92.   IF workbenchbase THEN CloseLibrary(workbenchbase)
  93.   IF iconbase THEN CloseLibrary(iconbase)
  94.   ->IF rdargs THEN FreeArgs(rdargs)
  95.   SELECT exception
  96.   CASE ERR_APPICON; WriteF('Error: Could not attach AppIcon to Workbench\n')
  97.   CASE ERR_DOBJ;    WriteF('Error: Could not get icon\n')
  98.   CASE ERR_LIB;     WriteF('Error: Could not open required library\n')
  99.   CASE ERR_PORT;    WriteF('Error: Could not create port\n')
  100.   CASE ERR_ARG;     WriteF('Error: ReadArgs()\n')
  101.   ENDSELECT
  102. ENDPROC
  103.  
  104. PROC oneshot()
  105.    StringF(argstring, '\s ', myargs[0])
  106.    FOR x:=0 TO appmsg.numargs-1
  107.       NameFromLock(appmsg.arglist[x].lock, nfl, 99)
  108.       AddPart(nfl, appmsg.arglist[x].name, 100)
  109.       StrAdd(argstring, nfl)
  110.       StrAdd(argstring, ' ')
  111.    ENDFOR
  112.    StrAdd(argstring, '\0')
  113.    SystemTagList(argstring, NIL)
  114.    ->WriteF('\s', argstring)
  115. ENDPROC
  116.  
  117. PROC foreach()
  118.    FOR x:=0 TO appmsg.numargs-1
  119.       StringF(argstring, '\s ', myargs[0])
  120.       NameFromLock(appmsg.arglist[x].lock, nfl, 99)
  121.       AddPart(nfl, appmsg.arglist[x].name, 100)
  122.       StrAdd(argstring, nfl)
  123.       StrAdd(argstring, '\0')
  124.       SystemTagList(argstring, NIL)
  125.    ENDFOR
  126. ENDPROC
  127.